/*
 * www.7yangche.com Inc.
 * Copyright (c) 2012 All Rights Reserved.
 */
package cbh.tool.mybatis.page;

import java.util.Iterator;
import java.util.List;


/**
 * @author cyzhang
 *
 */
public class PageDefault<T> implements Page<T> {

    private int pageNum;

    private int pageSize;

    private List<T> data;

    private long count;

    public PageDefault(int pageNum, int pageSize, List<T> data, Long count) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.data = data;
        this.count = count;
    }
    
    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    @Override
    public int getPageNum() {
        return pageNum;
    }
    
    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    @Override
    public int getPageSize() {
        return pageSize;
    }
    
    public void setCount(Long count) {
        this.count = count;
    }

    @Override
    public long getCount() {
        return count;
    }
    
    public void setData(List<T> data) {
        this.data = data;
    }
    
    @Override
    public List<T> getData() {
        return data;
    }


    @Override
    public int getPageCount() {
        return ((int)(this.count % this.pageSize)) > 0 ?
            ((int)(this.count / this.pageSize) + 1) :
            ((int)(this.count / this.pageSize));
    }

    @Override
    public Iterator<T> iterator() {
        return this.data.iterator();
    }
    
    @Override
    public boolean hasNext() {
        return this.getPageNum() < this.getPageCount();
    }

}
